# Maintainer: Orhun Parmaksız <orhun@archlinux.org>
# Contributor: Chocobo1 <chocobo1 AT archlinux DOT net>

pkgname=zls
pkgver=0.10.0
_gitcommit=7ef224467ab2f3179058981740e942977892e7b9
pkgrel=3
pkgdesc="A language server for Zig"
arch=('loong64' 'x86_64')
url="https://github.com/zigtools/zls"
license=('MIT')
depends=('zig')
makedepends=('git')
source=(
  "${pkgname}::git+$url#commit=$_gitcommit"
  "${pkgname}-known-folders::git+https://github.com/ziglibs/known-folders"
  "${pkgname}-tracy::git+https://github.com/wolfpld/tracy"
  "pie-opt.patch"
)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'c8241efa5da3dc263b655acc5ae76d56577802693eb62c0cfb0e0ed8b88af08f')

prepare() {
  cd "${pkgname}"
  patch -Np1 -i "../pie-opt.patch"
  git submodule init
  git config submodule."src/known-folders".url "${srcdir}/${pkgname}"-known-folders
  git config submodule."src/tracy".url "${srcdir}/${pkgname}"-tracy
  git -c protocol.file.allow=always submodule update --init --recursive
}

build() {
  cd "$pkgname"
  DESTDIR="build" zig build \
    --prefix /usr \
    --search-prefix /usr \
    -Dtarget=native-linux.5.15-gnu \
    -Dcpu=baseline \
    -Drelease-safe \
    -Dpie=true
}

check() {
  cd "$pkgname"
  zig build test \
    -Dtarget=native-linux.5.15-gnu \
    -Dcpu=baseline \
    -Drelease-safe
}

package() {
  cd "$pkgname"
  cp -a build/* "$pkgdir"
  install -Dm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
  install -Dm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}

# vim: ts=2 sw=2 et:
